package com.wn.icloud.controller;

import com.wn.icloud.domain.BaseTreeEntityDomain;
import com.wn.icloud.service.BaseTreeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.Serializable;
import java.util.List;

/**
 * @author liguangcai
 * @date 2018/11/30 21:48
 */
public class BaseTreeController<T extends BaseTreeEntityDomain<T>,ID extends Serializable,S extends BaseTreeService<T, ID>> extends BaseController<T, ID, S>{

	@Autowired
	protected S treeService;

	@GetMapping("/tree")
	public List<T> getTree(@RequestParam ID id){
		if (StringUtils.isNoneBlank(String.valueOf(id))) {
			T entity = this.treeService.getOne(id);
			if (null!=entity) {
				return entity.getChildren();
			}
		}
		return this.treeService.getRoot();

	}

}
